{extend name='index@template/base'}{/extend}
{block name='style'}{/block}
{block name='script'}{/block}
{block name='content'}
<div class="wrapper">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-body">
                    <div id="toolbar">
                        <div class="btn-group pull-left mr10">
                            <a class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 添加个性化菜单</a>
                        </div>
                    </div>
                    <table id="table"
                           data-toggle="table"
                           data-show-refresh="true"
                           data-side-pagination="server"
                           data-pagination="true"
                           data-url="{:url('WechatMenu/index_data')}"
                    >
                        <thead>
                        <tr>
                            <th data-field="title">标题</th>
                            <!--<th data-field="group_name" data-sortable="true" data-align="right">所属用户组</th>-->
                            <th data-field="type"  data-formatter="formatType" data-align="right">是否生效</th>
                            <th data-field="create_time" data-align="right" data-formatter="formatDate">创建时间</th>
                            <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents" >操作</th>
                        </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->

        </div><!-- /.col -->
    </div><!-- /.row -->
</div>
{/block}
{block name='script_extra'}
<script>
    // <editor-fold defaultstate="collapsed" desc="添加">
    $('#add_btn').on('click',function(){
        layer_open('添加自定义菜单',"{:url('WechatMenu/add')}")
    })
    // </editor-fold>


    // <editor-fold defaultstate="collapsed" desc="操作">
    function formatOperate(value, row, index) {
        if (row.type == 2)
            return [
                '<button class="btn btn-success btn-sm row_push" href="javascript:void(0)">',
                ' 推送到微信',
                '</button>&nbsp;',
                '<button class="btn btn-warning btn-sm row_edit" href="javascript:void(0)">',
                '修改',
                '</button>&nbsp;',
                '<button class="btn btn-danger btn-sm row_delete" href="javascript:void(0)">',
                '删除',
                '</button>'
            ].join('');
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {
        'click .row_push': function (e, value, row, index) {
            layer.confirm('你确定要推送到微信吗？',{btn:['确定','取消']},function(){
                $.ajax({
                    dataType:'json',
                    data:{id:row.id},
                    url:"{:url('wechat/WechatMenu/push_to_online')}",
                    success:function(res){
                        if(res.success){
                            layer.msg(res.message);
                            $('#table').bootstrapTable('refresh');
                        }else{
                            layer.alert(res.message,{icon:5})
                        }
                    }
                })

            },function(){})
        },
        'click .row_edit': function (e, value, row, index) {
            layer_open('编辑',urlFormat("{:url('wechat/WechatMenu/edit')}")+"/id/"+row.id);
        },
        'click .row_delete': function (e, value, row, index) {
            layer.confirm('你确定要删除该选项吗？', {btn: ['确定', '取消']}, function () {
                $.ajax({
                    dataType: 'json',
                    data: {id: row.id},
                    url: "{:url('wechat/WechatMenu/delete')}",
                    success: function (res) {
                        if (res.success) {
                            layer.msg(res.message);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.alert(res.message, {icon: 5})
                        }
                    }
                })
            })
        }
    };

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="定义状态">
    function formatType(value) {
        if (parseInt(value) == 1) {
            return '<i class="fa fa-check-circle text-green" title="已在微信端生效">已在微信端生效</i>';
        }
        if (parseInt(value) == 2) {
            return '<i class="fa fa-minus-circle text-yellow" title="未在微信端生效">未在微信端生效</i>';
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="定义时间">
    function formatDate(value) {
        var date = new Date(parseInt(value) * 1000);
        Y = date.getFullYear() + '-';
        M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        D = (date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
        h = (date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
        m = (date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
        s = (date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
        return Y + M + D + h + m + s;
    }
    // </editor-fold>
</script>

{/block}